Hello, I want to create a trigger (pretty simple) that give an error message when I tried to write in attribute let's call it "result" and that should happen just for inlink objects. i need help in DXL script "dxl_code" , is that right , I am realy lost in Trigger ?
void Trigger_Delete(string state)
{
...................
}
void Trigger_set(string state)
{
..............
string dxl_code =
"Module m = current
Object o = current
for o in entire m do {
string h = o."result"
Link L; for L in o <-"*" do {
if (h != "") {
print "this object is in_link , do not write" "\n"
}
}
}"
Trigger trg
trg = trigger(state, module->attribute->state, pre, write, 2, dxl_code)
}
Trigger_set("result")
or should I make my trg trg = trigger(state, module->state->link, pre, write, 2, dxl_code)
Regards, Neven Control17 - Fri Sep 15 05:26:39 EDT 2017 |
Re: Trigger for inlink objects Hi Neven, so, your goal is to prevent that a user modifies an object if the object has(!) an in-link, right? ("*is* an in-link is not correct, an object is not a link). That means the event that you want to prevent is not a link creation but an attribute modification. So you will need a trigger that reacts on the change of an attribute of a specific object. In this trigger you only want to check whether the object that has just been changed has an in link (you are not interested whether any(!) object in the database has an in-link, so your loop 'for o in entire mod' does not lead you into the right directon). I have no idea for what you need the attribute "result", so I'll ignore this.
I assume that you want to create this trigger not only for a specific module but for all modules in one of your projects.
What shall the trigger do? The code in a normal editor would look like this
// variable o shall contain the object that has just been changed, the object that was responsible for starting the current trigger
Object o = object current Trigger
LinkRef LR; for LR in o <-"*" do {
// I am in the loop, so I found an In-Link-Reference.
// so, the user was not allowed to change any attribute of the object
print "this object has an in_link, do not write\n"
// set the trigger status to state that an error occurred
set trigPreConFail
// stop the trigger script, no further checks necessary
halt
}
// the trigger script did not stop, so there was no in-link. Everything is fine
set trigPreConPass
How to install a trigger?
string triggerName = "preventModificationIfInLink"
string projectName = "/NevensProject"
Project p = project projectName
string dxl_code= ... see below ...
Trigger T
// In the current "project", install a trigger for all "formal" modules, that checks for changes in "all" "attribute"s
// the trigger must be started before ("pre") the object is changed (called "save"d here)
// the code to be executed is stored in dxl_code
// Prio: 2
T = trigger (triggerName, project->formal->attribute->all, pre, save, 2, dxl_code)
if (null T) print "Trigger " triggerName " could not be installed!\n"
One problem is: how to store the code into the variable dxl_code. But there are " inside the code. -> you must "escape" every " in the code by a backslash \, so every " becomes a \". so, the missing lines above are
string dxl_code="
// variable o shall contain the object that has just been changed, the object that was responsible for starting the current trigger
Object o = object current Trigger
LinkRef LR; for LR in o <-\"*\" do {
// I am in the loop, so I found an In-Link-Reference.
// so, the user was not allowed to change any attribute of the object
print \"this object has an in_link, do not write\n\"
// set the trigger status to state that an error occurred
set trigPreConFail
// stop the trigger script, no further checks necessary
halt
}
// the trigger script did not stop, so there was no in-link. Everything is fine
set trigPreConPass
"
|
Re: Trigger for inlink objects Mike.Scharnow - Tue Sep 19 12:50:57 EDT 2017 Hi Neven, so, your goal is to prevent that a user modifies an object if the object has(!) an in-link, right? ("*is* an in-link is not correct, an object is not a link). That means the event that you want to prevent is not a link creation but an attribute modification. So you will need a trigger that reacts on the change of an attribute of a specific object. In this trigger you only want to check whether the object that has just been changed has an in link (you are not interested whether any(!) object in the database has an in-link, so your loop 'for o in entire mod' does not lead you into the right directon). I have no idea for what you need the attribute "result", so I'll ignore this.
I assume that you want to create this trigger not only for a specific module but for all modules in one of your projects.
What shall the trigger do? The code in a normal editor would look like this
// variable o shall contain the object that has just been changed, the object that was responsible for starting the current trigger
Object o = object current Trigger
LinkRef LR; for LR in o <-"*" do {
// I am in the loop, so I found an In-Link-Reference.
// so, the user was not allowed to change any attribute of the object
print "this object has an in_link, do not write\n"
// set the trigger status to state that an error occurred
set trigPreConFail
// stop the trigger script, no further checks necessary
halt
}
// the trigger script did not stop, so there was no in-link. Everything is fine
set trigPreConPass
How to install a trigger?
string triggerName = "preventModificationIfInLink"
string projectName = "/NevensProject"
Project p = project projectName
string dxl_code= ... see below ...
Trigger T
// In the current "project", install a trigger for all "formal" modules, that checks for changes in "all" "attribute"s
// the trigger must be started before ("pre") the object is changed (called "save"d here)
// the code to be executed is stored in dxl_code
// Prio: 2
T = trigger (triggerName, project->formal->attribute->all, pre, save, 2, dxl_code)
if (null T) print "Trigger " triggerName " could not be installed!\n"
One problem is: how to store the code into the variable dxl_code. But there are " inside the code. -> you must "escape" every " in the code by a backslash \, so every " becomes a \". so, the missing lines above are
string dxl_code="
// variable o shall contain the object that has just been changed, the object that was responsible for starting the current trigger
Object o = object current Trigger
LinkRef LR; for LR in o <-\"*\" do {
// I am in the loop, so I found an In-Link-Reference.
// so, the user was not allowed to change any attribute of the object
print \"this object has an in_link, do not write\n\"
// set the trigger status to state that an error occurred
set trigPreConFail
// stop the trigger script, no further checks necessary
halt
}
// the trigger script did not stop, so there was no in-link. Everything is fine
set trigPreConPass
"
Hello Mike, thank u for your replay, yes my goal is to prevent that a user modifies an object if the object has(!) an in-link, but just when the user try to modify specific attribute "result" and I want to make the Trigger for specific module
I did so , is that possible with modulNr ?
string triggerName = "preventModificationIfInLink"
string modulNr = "009g8765"
Module m = edit modulNr
string dxl_code="
// variable o shall contain the object that has just been changed, the object that was responsible for starting the current trigger
Object o = object current Trigger
LinkRef LR; for LR in o <-\"*\" do {
// I am in the loop, so I found an In-Link-Reference.
// so, the user was not allowed to change result attribute of the object
string h = o.\"result\"
if (h != \"\") {
print \"this object has an in_link, do not write\n\"
// set the trigger status to state that an error occurred
set trigPreConFail
}
// stop the trigger script, no further checks necessary
halt
}
// the trigger script did not stop, so there was no in-link. Everything is fine
set trigPreConPass
"
Trigger T
T = trigger (triggerName, module->modulNr->attribute->"result", pre, save, 2, dxl_code)
if (null T) print "Trigger " triggerName " could not be installed!\n"
Regards,
|
Re: Trigger for inlink objects Control17 - Thu Sep 21 03:51:25 EDT 2017 Hello Mike, thank u for your replay, yes my goal is to prevent that a user modifies an object if the object has(!) an in-link, but just when the user try to modify specific attribute "result" and I want to make the Trigger for specific module
I did so , is that possible with modulNr ?
string triggerName = "preventModificationIfInLink"
string modulNr = "009g8765"
Module m = edit modulNr
string dxl_code="
// variable o shall contain the object that has just been changed, the object that was responsible for starting the current trigger
Object o = object current Trigger
LinkRef LR; for LR in o <-\"*\" do {
// I am in the loop, so I found an In-Link-Reference.
// so, the user was not allowed to change result attribute of the object
string h = o.\"result\"
if (h != \"\") {
print \"this object has an in_link, do not write\n\"
// set the trigger status to state that an error occurred
set trigPreConFail
}
// stop the trigger script, no further checks necessary
halt
}
// the trigger script did not stop, so there was no in-link. Everything is fine
set trigPreConPass
"
Trigger T
T = trigger (triggerName, module->modulNr->attribute->"result", pre, save, 2, dxl_code)
if (null T) print "Trigger " triggerName " could not be installed!\n"
Regards,
Hi! According to the chapter "Trigger level assembly", I would say that you install the trigger by using the syntax Trigger T = trigger (nameOfMyTrigger, project -> nameOfMyProject -> module -> nameOfMyModule -> attribute -> nameOfMyAttribute, pre, save, 2, dxl_code) I played around a bit the syntax, especially if the module is not in the root folder of the module and came to the following script
string nameOfMyTrigger = "preventModificationIfInLink"
string nameOfMyProject = "Demo"
string pathToModuleInProject = "f1/f2" // if the module is in the root folder of the project, pathToModuleInProject = ""
string nameOfMyModule = "MyMod"
string nameOfMyAttribute "result"
current = project ("/" nameOfMyProject)
current = folder ("/" nameOfMyProject "/" pathToModuleInProject)
Trigger T = trigger (nameOfMyTrigger, project -> nameOfMyProject -> module -> nameOfMyModule -> attribute -> nameOfMyAttribute, pre, save, 2, dxl_code)
if null T then error "trigger could not be created, perhaps it already exists? Then delete it before recreation"
As you created the trigger on module level, you need to delete all triggers of the module, not of the project (see the other thread):
// delete all existing triggers.
Module m = read ("/" nameOfMyProject "/" pathToModuleInProject "/" nameOfMyModule, true, false)
if null m then error "could not open the module"
Trigger Td
for Td in m do delete Td
close m
Of course, you can combine the two parts.
About your trigger code, I am not sure if you really need to get the content of result. Do you want to allow the change if the user emptied the result and only want to prevent the change if the user changed the value to a non-empty result? If so, your code is correct, I think. Instead of writing the attribute name "result" into the code, you could also create a variable "string attributeJustChanged = attribute current Trigger" |
Re: Trigger for inlink objects Mike.Scharnow - Thu Sep 21 04:45:20 EDT 2017 Hi! According to the chapter "Trigger level assembly", I would say that you install the trigger by using the syntax Trigger T = trigger (nameOfMyTrigger, project -> nameOfMyProject -> module -> nameOfMyModule -> attribute -> nameOfMyAttribute, pre, save, 2, dxl_code) I played around a bit the syntax, especially if the module is not in the root folder of the module and came to the following script
string nameOfMyTrigger = "preventModificationIfInLink"
string nameOfMyProject = "Demo"
string pathToModuleInProject = "f1/f2" // if the module is in the root folder of the project, pathToModuleInProject = ""
string nameOfMyModule = "MyMod"
string nameOfMyAttribute "result"
current = project ("/" nameOfMyProject)
current = folder ("/" nameOfMyProject "/" pathToModuleInProject)
Trigger T = trigger (nameOfMyTrigger, project -> nameOfMyProject -> module -> nameOfMyModule -> attribute -> nameOfMyAttribute, pre, save, 2, dxl_code)
if null T then error "trigger could not be created, perhaps it already exists? Then delete it before recreation"
As you created the trigger on module level, you need to delete all triggers of the module, not of the project (see the other thread):
// delete all existing triggers.
Module m = read ("/" nameOfMyProject "/" pathToModuleInProject "/" nameOfMyModule, true, false)
if null m then error "could not open the module"
Trigger Td
for Td in m do delete Td
close m
Of course, you can combine the two parts.
About your trigger code, I am not sure if you really need to get the content of result. Do you want to allow the change if the user emptied the result and only want to prevent the change if the user changed the value to a non-empty result? If so, your code is correct, I think. Instead of writing the attribute name "result" into the code, you could also create a variable "string attributeJustChanged = attribute current Trigger" Hello Mike, attribute "result" is empty and should stay empty when I inlink have , actually I want to prevent writting in this attribute. should I take the opposite ( is equal = ) ?
Regards, Neven
|
Re: Trigger for inlink objects Control17 - Fri Sep 22 07:30:12 EDT 2017 Hello Mike, attribute "result" is empty and should stay empty when I inlink have , actually I want to prevent writting in this attribute. should I take the opposite ( is equal = ) ?
Regards, Neven
If you just want to prevent that a user changes anything in "result", you only need to check if the object has an inlink. If there is an inlink, the user is not allowed to do anything in the attribute. So, the script from the second post of this thread should do exactly what you want.. |
Re: Trigger for inlink objects Mike.Scharnow - Fri Sep 22 07:51:13 EDT 2017 If you just want to prevent that a user changes anything in "result", you only need to check if the object has an inlink. If there is an inlink, the user is not allowed to do anything in the attribute. So, the script from the second post of this thread should do exactly what you want.. thnak u very much , you are right.
Regards, Neven |